package concurrent.chapter02;

/**
 * @Comment:打印任务类
 * @Author:Shem
 * @Date:2019/5/25
 */
public class PrintTask implements Runnable {

    private volatile int count = 1;
    private final int total = 100;

    @Override
    public void run() {
        while (count <= total) {
            synchronized (this) {
                System.out.println(String.format("线程名：%s，i:  %s", Thread.currentThread().getName(), count));
                count++;
                this.notifyAll();
                try {
                    if (count <= total)
                        this.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
